from flask import Blueprint

admin_bp = Blueprint("admin_bp",__name__,url_prefix="/admin")

from .views import *

# 是请求这个蓝图的时候才执行拦截
@admin_bp.before_request
def before_request():
    """拦截普通用户和未登录能够进入后台管理首页"""
    if request.url.endswith(url_for("admin_bp.admin_index")):
        user_id = session.get("user_id")
        is_admin = session.get("is_admin")
        # 未登录或者不是管理员
        if not user_id or not is_admin:
            return redirect('/')